<?php
namespace Guestbook\Controller;
use Common\Controller\Base;
class IndexController extends Base {
    private $Guestbook = NULL;
    private $Messageboard = NULL;

    protected function _initialize() {
        parent::_initialize();
        $this->Guestbook = D('Guestbook/Guestbook');
        $this->Messageboard = D('Guestbook/Messageboard');
    }
    public function index() {
        //条件
        $where['status'] = array('eq','1');
        $count = $this->Guestbook->where($where)->count();
        $page = $this->page($count, 5);
        $data = $this->Guestbook->where($where)->limit($page->firstRow . ',' . $page->listRows)->order(array("listorder" => "DESC", "id" => "DESC"))->select();
        foreach ($data as &$val){
            switch ($val['zhuti']){
                case '1':
                    $val['zhuti']='高补文科';
                    break;
                case '2':
                    $val['zhuti']='高补理科';
                    break;
                case '3':
                    $val['zhuti']='艺考补习';
                    break;
                case '4':
                    $val['zhuti']='中补';
                    break;
                case '5':
                    $val['zhuti']='高三应届';
                    break;
                case '6':
                    $val['zhuti']='初三应届s';
                    break;
            }
            if($val['updatetime']=='0'){
                $val['updatetime']="";
            }else{
                $val['updatetime']=date('Y-m-d H:i:s');
            }
        }
        $this->assign('list', $data);
        $this->assign("Page", $page->show());
        $this->assign('count', $count);
        $this->display();
    }
    public function addMessage() {
        if (IS_POST) {
            $post = I('post.', NULL, 'htmlspecialchars');
            if ($this->Messageboard->addCandidates($post)) {
                $this->success('你的留言提交成功！正在等待审核！', U('Index/index'));
            } else {
                $error = $this->Messageboard->getError();
                $this->error($error ? $error : '提交失败！');
            }
        } else {
            
        }
    }

}
